#include "mainscence.h"
#include "ui_mainscence.h"
#include<QPainter>
#include "mypushbutton.h"
#include<QDebug>
#include<QTimer>
#include<QSound>  //Coin flips // QT       += core gui multimedia

MainScence::MainScence(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainScence)
{
    ui->setupUi(this);

    setFixedSize(320,590);
    setWindowIcon(QIcon(":/res/Coin0001.png"));
    setWindowTitle("MySpecialGame");
    connect(ui->actionQuit,&QAction::triggered,[=](){
        this->close();
    });

    //准备开始按钮的音效
    QSound*startSoud=new QSound(":/res/TapButtonSound.wav",this);
//    startSoud->setLoops(10);
//    startSoud->play();


    //开始按钮
    MyPushButton * startBtn = new MyPushButton(":/res/MenuSceneStartButton.png");
    startBtn->setParent(this);
    startBtn->move(this->width()*0.5 - startBtn->width()*0.5,this->height()*0.7);

    //实例化选择关卡场景
    chooseScence=new ChooseLevelScence;

    //监听选择关卡的返回按钮的信号
    connect(chooseScence,&ChooseLevelScence::chooseScenceBack,this,[=](){
        this->setGeometry(chooseScence->geometry());
        chooseScence->hide();
        this->show();
    });

    connect(startBtn,&MyPushButton::clicked,[=](){
        qDebug()<<"点击开始了";
        startSoud->play();
        //做一个弹起的特效
       startBtn->zoom1();
       startBtn->zoom2();

       //进入到选择关卡场景中
       QTimer::singleShot(300,this,[=](){
           //设置choosescence 场景位置
           chooseScence->setGeometry(this->geometry());
           this->hide();
           chooseScence->show();
       });
    });

}



 void MainScence::paintEvent(QPaintEvent*)
    {
        QPainter painter(this);
        QPixmap pix;
        pix.load(":/res/PlayLevelSceneBg.png");
        painter.drawPixmap(0,0,this->width(),this->height(),pix);
        //画背景图标
        pix.load(":/res/Title.png");
        pix=pix.scaled(pix.width()*0.5,pix.height()*0.5);
        painter.drawPixmap(10,30,pix);

    }






MainScence::~MainScence()
{
    delete ui;
}
























